<?php
/**
 * Created by PhpStorm.
 * User: huyi
 * Date: 2018/1/26
 * Time: 16:40
 */
require_once __DIR__ . './../vendor/autoload.php';use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$exchange_name = 'direct_logs';
$connection    = new AMQPStreamConnection('localhost', 5672, 'huyi', 'huyi123');
$channel       = $connection->channel();

$channel->exchange_declare($exchange_name, 'direct', false, false, false);

$severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info';

$data = implode(' ', array_slice($argv, 2));
if(empty($data)){
    $data = "Hello World!";
}

$msg = new AMQPMessage($data);

$channel->basic_publish($msg, $exchange_name, $severity);
echo " [x] Sent ",$severity,':',$data," \n";

$channel->close();
$connection->close();

